package com.pzy.base.configuration;

import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class SpringDocConfiguration {

        @Bean
        public OpenAPI springDocOpenAPI(AppProperty appProperty) {
                log.debug("springDocOpenAPI 初始化, swagger ui 访问地址: http://localhost:{}{}", appProperty.getServerPort(),
                                appProperty.getSwaggerUiPath());

                return new OpenAPI()
                                .info(new Info().title("SpringShop API")
                                                .description("通用业务接口状态码(非http响应状态码). <br/>200: 执行成功. <br/>400: 请求参数不符合接口要求. <br/> 4000: 数据未通过验证/预期业务异常. <br/>404: 资源未找到异常. <br/>405: 调用端发起了不支持的请求方式(如: 接口仅支持POST, 调用端使用GET). <br/>500: 服务内部发生非预期异常")
                                                .version("v0.0.1")
                                                .license(new License().name("Apache 2.0").url("http://springdoc.org")))
                                .externalDocs(new ExternalDocumentation()
                                                .description("SpringShop Wiki Documentation")
                                                .url("https://springshop.wiki.github.org/docs"));
        }
}
